var app = angular.module('indexApp', []);
app.controller('indexController', function($scope, $http) {
	$scope.input = {
		"username" : "18521355675",
		"password" : "123456"
	};
	$scope.clear = function(item) {
		$scope.input[item] = '';
	};
	$scope.signin = function() {
		var username = $scope.input.username.trim();
		if (username.length != 11 || isNaN(username)) {
			alert("用户名输入有误！");
			return;
		}
		var password = $scope.input.password.trim();
		if (password.length < 6 || password.length > 12) {
			alert("密码输入有误！");
			return;
		}
		$http({
	        method: 'POST',
	        url: '../query.do',
	        data: { "queryID": "user.S002", "condition": [username, password] },  
	        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },  
           	transformRequest: function(obj) {
            	var str = [];
            	for (var s in obj) {
                	str.push(encodeURIComponent(s) + "=" + encodeURIComponent(obj[s]));  
            	}
            	return str.join("&");  
           	}
	    }).then(
	    	function successCallback(response) {
	    		if (response.data.count == 0) {
	    			alert("用户名或密码错误！");
	    		} else {
	    			window.location.href = 'homepage.do';
	    		}
	        }, function errorCallback(response) {
	        	console.log(response);
	    });
	};
	$scope.signup = function() {
		window.location.href = 'sign.html';
	};
	$scope.password_reset = function() {
		window.location.href = 'forgot_password.html';
	};
});